<template>
  <view class="good-list">
    <uni-list>
      <uni-list-item v-for="(item, index) in list" :key="index" style="align-items: center">
        <template slot="body">
          <view class="u-cell-group" @click="navigateTo(item)">
            <view class="title">{{$t('印章名称')}}：{{ item.name }}</view>
            <view>{{$t('所属组织')}}：{{ item.department }}</view>
            <view>{{$t('印章管理员')}}：{{ item.transactor }}</view>
            <view>{{$t('印章审计员')}}：{{ item.auditorUser }}</view>
            <view>{{$t('印章类型')}}：{{ item.type }}</view>
            <view v-if="item.device">{{$t('关联实体章')}}：{{ item.device }}</view>
            <view>
              {{$t('证书状态')}}：
              <u-tag v-if="!item.certificateStatus" size="mini" :text="$t('未关联')" type="info"></u-tag>
              <u-tag
                v-else
                :text="computerTypeList(item.certificateStatus, 'text')"
                :type="computerTypeList(item.certificateStatus, 'color')"
                size="mini"
              ></u-tag>
            </view>
            <view v-if="item.certificateEndTime">
              {{$t('证书过期时间')}}：{{ computerTime(item.certificateEndTime) }}
            </view>
            <view>{{$t('注册日期')}}：{{ item.createDate }}</view>
          </view>
        </template>
        <template slot="footer">
          <view class="footer">
            <u-tag style="width: 150rpx" :text="$t('使用记录')" @click="usageRecord(item)" />
          </view>
        </template>
      </uni-list-item>
    </uni-list>
  </view>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex'

export default {
  computed: {
    ...mapGetters(['userInfo', 'api']),
    computerTypeList() {
      return (code, type) => {
        let item = this.statusList.find((item) => item.key === code)
        if (type === 'text') {
          return item.value
        } else if (type === 'color') {
          return item.color
        } else if (type === 'remark') {
          return item.remark
        }
      }
    },
    computerTime() {
      return (time) => {
        let str = ''
        for (var i = 0; i < time.length; i++) {
          if (i === 3) {
            str += time[i] + '-'
          } else if (i === 5) {
            str += time[i] + '-'
          } else if (i === 7) {
            str += time[i] + ' '
          } else if (i === 9) {
            str += time[i] + ':'
          } else if (i === 11) {
            str += time[i] + ':'
          } else {
            str += time[i]
          }
        }
        return str
      }
    }
  },
  props: {
    list: {
      type: [Array],
      default() {
        return []
      }
    },
    statusList: {
      type: [Array],
      default() {
        return []
      }
    }
  },
  data() {
    return {}
  },
  mounted() {
  },
  methods: {
    usageRecord(row) {
      //console.log(row);
      uni.navigateTo({
        url: '../../electronicSeal/electronUsageRecord/electronUsageRecord',
        events: {
          confirm(data) {
            //console.log(data);
          }
        },
        success(res) {
          res.eventChannel.emit('pagePramas', { sealId: row.sealId, type: '电子印章' })
        }
      })
    },
    navigateTo(item) {
      if (item.title === '设备拆卸') {
        uni.navigateTo({
          url: '../dismounting/dismounting?id=' + item.id
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.good-list {
  background-color: #fff;
  width: 100%;

  .u-cell-group {
    font-size: 28rpx;
    color: #888;
    line-height: 48rpx;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    flex-direction: column;

    .title {
      font-weight: bold;
      color: #000;
    }

    .error-item {
      color: red;
    }
  }

  .slot-content {
    padding: 20rpx 30rpx;
  }

  .footer {
    margin: auto;
  }
}
</style>
